//
//  IncomeDetailsViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/10.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "HMSegmentedControl.h"
#import "IncomeDetailsListCell.h"
#import "CommonDateSectionHeader.h"


#import "IncomeDetailsViewController.h"

@interface IncomeDetailsViewController ()<UITableViewDelegate,
UITableViewDataSource>

@property (strong, nonatomic) HMSegmentedControl *segmentedControl;


@property (strong, nonatomic) UITableView *tableview;

@property (nonatomic, assign) NSInteger type;


@end

@implementation IncomeDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}

- (void)initView {

    self.title = @"收支明细";
    self.type = 0;
    self.view.backgroundColor = UIColorHex(0xf1f1f1);


    [self.view addSubview:self.segmentedControl];
    [self.view addSubview:self.tableview];

    self.segmentedControl.frame = CGRectMake(0 , 0, TTScreenWidth, 50);

    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.segmentedControl.mas_bottom);
    }];

    [self.tableview reloadData];

    WEAKSELF
    [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {

//        [weakSelf refresh];
//        weakSelf.type = (PPApprenticType)index;
//        [weakSelf request_ApprenticeList];
    }];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    IncomeDetailsListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"IncomeDetailsListCellID" forIndexPath:indexPath];
//    [cell fillCellWithModel:self.AppreticeListArray[indexPath.row]];
    return cell;
}

#pragma mark sectionheader
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    CommonDateSectionHeader *headView  =  [[NSBundle mainBundle] loadNibNamed:@"CommonDateSectionHeader"owner:nil options:nil].firstObject;
    return  headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 40;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 6;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}


- (HMSegmentedControl *)segmentedControl {
    
    if (!_segmentedControl) {
        
        _segmentedControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"收支明细", @"订单明细"]];
        _segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
        _segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
        _segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleFixed;
        
        _segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName:UIColorHex(0x333333), NSFontAttributeName :[UIFont systemFontOfSize:14]};
        _segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName:UIColorHex(0x24c77e),NSFontAttributeName : [UIFont boldSystemFontOfSize:14]};
        _segmentedControl.selectionIndicatorColor = UIColorHex(0x24c77e);
        _segmentedControl.backgroundColor = [UIColor whiteColor];
        _segmentedControl.selectionIndicatorHeight = 2;
                
    }
    return _segmentedControl;
}

- (UITableView *)tableview {
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.backgroundColor =  UIColorHex(0xf1f1f1);

        _tableview.showsHorizontalScrollIndicator = NO;
        _tableview.showsVerticalScrollIndicator = NO;
        
        _tableview.estimatedSectionHeaderHeight = 0;
        _tableview.estimatedSectionFooterHeight = 0;
        _tableview.estimatedRowHeight = 0;
        
        [_tableview registerNib:[UINib nibWithNibName:@"IncomeDetailsListCell" bundle:nil] forCellReuseIdentifier:@"IncomeDetailsListCellID"];

    }
    return _tableview;
}

@end
